package com.guigusuqi.app.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigusuqi.app.entity.Department;
import com.guigusuqi.app.entity.VO.DepartmentQuery;
import com.guigusuqi.app.service.DepartmentService;
import com.guigusuqi.commonutils.vo.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 科室管理 前端控制器
 * </p>
 *
 * @author suqi
 * @since 2022-04-05
 */
@RestController
@RequestMapping("/yy/department")
@Api(tags = {"wx-科室小程序管理"})
public class DepartmentController
{
    @Resource
    private DepartmentService departmentService;

    @ApiOperation(value = "查询所有科室信息")
    @GetMapping("findAll")
    public Result findAllTeacher()
    {
        List<Department> list = departmentService.list(null);
        return Result.success().data("item",list);
    }
    //条件查询
    @ApiOperation(value = "条件查询所有科室信息")
    @PostMapping("DepartmentCondition")
    public Result pageTeacherCondition(
                                  //得使用post提交方式
                                  @RequestBody(required = false) DepartmentQuery departmentQuery)
    {
        //构建一个条件
        QueryWrapper<Department> wrapper = new QueryWrapper<>();
        //多条件组合查询
        //wrapper
        //mybatis学过动态sql
        //判断条件值是否为空，如果不为空则拼接条件
        String name = departmentQuery.getName();
        String address = departmentQuery.getAddress();

        if (!StringUtils.isEmpty(name)) {
            wrapper.like("name", name);
        }
        if (!StringUtils.isEmpty(address)) {
            wrapper.eq("address", address);
        }
        List<Department> list = departmentService.list(wrapper);

        //这里也可以使用两次data来传两次数据
        return Result.success().data("item",list);
    }
}

